﻿<UserControl x:Class="XbdSoft.WPFVersion.View.RecommendDownloadView"
     xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
             xmlns:WPFVersion="clr-namespace:XbdSoft.WPFVersion.ViewModel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:interopControl="clr-namespace:XbdSoft.InteropControls;assembly=XbdSoft.InteropControls"
             mc:Ignorable="d" Loaded="UserControl_Loaded" Name="Root" FontSize="12"
              d:DesignHeight="400" d:DesignWidth="600">
    <Grid Margin="0"  Name="layoutRoot" >
        <Grid.Resources>
            <WPFVersion:StringArrayConverter x:Key="stringArrayConverter"></WPFVersion:StringArrayConverter>
            <WPFVersion:ImageSourceConverter x:Key="imageSourceConverter"></WPFVersion:ImageSourceConverter>
            <WPFVersion:AgesConverter x:Key="agesConverter"/>
            <Style x:Key="imageButton" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border BorderThickness="0" BorderBrush="Gray" Background="{TemplateBinding Background}">
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style TargetType="{x:Type ListBoxItem}"> 
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#A2D2EB"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <Style TargetType="Button" x:Key="refreshButton">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border BorderThickness="0" BorderBrush="Gray" >
                                <Border.Background>
                                    <ImageBrush ImageSource="/Images/icon_refresh.png">
                                    </ImageBrush>
                                </Border.Background>
                                <Border.Triggers> 
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" >
                                            <Setter.Value>
                                                <ImageBrush ImageSource="/Images/icon_refresh_hover.png">
                                                </ImageBrush>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </Border.Triggers>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
    	<Grid.Background>
    		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    			<GradientStop Color="#FFA0E8FF" Offset="0"/>
    			<GradientStop Color="#FFFEFEFE" Offset="1"/>
    		</LinearGradientBrush>
    	</Grid.Background>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" MaxWidth="250" MinWidth="100"></ColumnDefinition>
            <ColumnDefinition Width="2"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height=".6*"></RowDefinition>
            <RowDefinition Height=".4*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid Grid.Column="0" Grid.RowSpan="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="2"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            <ListBox Name="recommendCategoryListView" 
                      DisplayMemberPath="Name" 
                      SelectionMode="Single"
                      ItemsSource="{Binding Path=RecommendCategories,Mode=OneWay}"
                      SelectedIndex="{Binding Path=SelectedCategoryIndex,Mode=TwoWay}"
                      BorderThickness="0" Padding="0" Margin="0" Grid.Row="0" Background="Transparent">
            </ListBox>
            <!--<GridSplitter Grid.Row="1" Margin="0" Padding="0"  Background="Gray" VerticalAlignment="Stretch"></GridSplitter>-->
            <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Vertical">
                <WindowsFormsHost x:Name="winMediaPlayerHost" Width="150" Height="65"  Visibility="Collapsed">
                    <interopControl:WinMediaPlayer x:Name="winMediaPlayer" ></interopControl:WinMediaPlayer>
                </WindowsFormsHost>
            </StackPanel>
        </Grid>
        <Border Margin="0" Padding="0" Background="Gray" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2"></Border>
        <DockPanel  Grid.Column="2" Grid.Row="0"  LastChildFill="True" Background="Transparent">
            <StackPanel Orientation="Horizontal"  DockPanel.Dock="Top" Height="25" VerticalAlignment="Center">
                <CheckBox Height="16" HorizontalAlignment="Left" Margin="10,4,0,0"  Name="SelectAllCheckbox" Content="全选" VerticalAlignment="Top" 
                        Command="{Binding SelectAllResourceCommand}" CommandParameter="{Binding ElementName=SelectAllCheckbox,Path=IsChecked}"/>
                <CheckBox Height="16" HorizontalAlignment="Left"  Margin="0,4,0,0" Name="SelectOthersCheckbox" Content="反选" VerticalAlignment="Top" 
                        Command="{Binding SelectOthersResourceCommand}"/> 
                <Button Name="DownloadSelectedButton" Style="{StaticResource imageButton}" Margin="5,0,0,0"  Cursor="Hand" ToolTip="下载已选"  Width="20" Height="16"
                        Command="{Binding DownloadAllSelectedResourceCommand}">
                    <Button.Background>
                        <ImageBrush ImageSource="/Images/download.png">
                        </ImageBrush>
                    </Button.Background>
                </Button>
                <Button Name="RefreshSelectedButton" Style="{StaticResource imageButton}" Margin="5,0,0,0"  Cursor="Hand" ToolTip="刷新"  Width="20" Height="20"
                        Command="{Binding RefreshResourceCommand}">
                    <Button.Background>
                        <ImageBrush ImageSource="/Images/icon_refresh.png">
                        </ImageBrush>
                    </Button.Background>
                </Button>
            </StackPanel>

            <ListBox Name="MainListBox"
                 SelectionMode="Single" ItemsSource="{Binding Path=SelectedCategory.AudioResources,Mode=OneWay}"
                 SelectedIndex="{Binding Path=SelectedResourceIndex,Mode=TwoWay}" Background="Transparent" BorderBrush="LightBlue">
                <ListBox.ItemTemplate >
                    <DataTemplate>
                        <Border BorderBrush="LightBlue" BorderThickness="0,0,0,1" Padding="2,2,2,2">
                            <Grid HorizontalAlignment="Stretch" Width="550" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition Width="50"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="100"/>
                                </Grid.ColumnDefinitions>
                                <CheckBox Name="SelectToDownloadCheckBox" IsChecked="{Binding Path=Selected,Mode=TwoWay}" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" />
                                <Image Stretch="Uniform" Grid.Column="1" Grid.Row="0" Source="{Binding Path=ThumbnailImgUrl,Converter={StaticResource imageSourceConverter}}"></Image>
                                <DockPanel  Grid.Column="2" Grid.Row="0" LastChildFill="True">
                                    <TextBlock  DockPanel.Dock="Top" Padding="5,0,0,0" Width="370" TextWrapping="Wrap" Text="{Binding Title}"></TextBlock>
                                    <Grid VerticalAlignment="Center">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="3.3*"/>
                                            <ColumnDefinition Width="3.3*"/>
                                            <ColumnDefinition Width="3.3*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" HorizontalAlignment="Center"  Foreground="Gray">
                                    <TextBlock.Text>
                                        <Binding Path="Time" StringFormat="时间:{0}"></Binding>
                                    </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Grid.Column="1" HorizontalAlignment="Center" Foreground="Gray">
                                    <TextBlock.Text>
                                        <Binding Path="BrowserCount" StringFormat="浏览次数:{0}"></Binding>
                                    </TextBlock.Text>
                                        </TextBlock>
                                        <!--<Image Grid.Column="2" HorizontalAlignment="Center" Stretch="Uniform" Source="/Images/yc.gif"></Image>-->
                                    </Grid>
                                </DockPanel>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Column="3" Grid.Row="0">
                                    <Button Style="{StaticResource imageButton}"  Margin="2,0,2,0" Cursor="Hand" ToolTip="试听" Width="20" Height="16"
                                        Command="{Binding ElementName=Root, Path=TryListenCommand}" CommandParameter="{Binding ID}"
                                        >
                                        <Button.Background>
                                            <ImageBrush ImageSource="/Images/trylisten.png">
                                            </ImageBrush>
                                        </Button.Background>
                                    </Button>
                                    <Button  Style="{StaticResource imageButton}" Margin="2,0,2,0" Cursor="Hand" ToolTip="下载"  Width="20" Height="16"
                                          Command="{Binding ElementName=Root, Path=DownloadCommand}" CommandParameter="{Binding ID}">
                                        <Button.Background>
                                            <ImageBrush ImageSource="/Images/download.png">
                                            </ImageBrush>
                                        </Button.Background>
                                    </Button>
                                </StackPanel>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DockPanel>
        
        <GroupBox Grid.Column="2" Grid.Row="1" Header="详细信息："  Padding="2" BorderBrush="LightBlue" Background="Transparent">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" HorizontalAlignment="Right" Grid.Row="0"  Foreground="Gray" Text="作者：">
                </TextBlock>
                <TextBlock Grid.Column="1" Grid.Row="0"  Text="{Binding Path=SelectedResource.Author,Mode=OneWay}">
                </TextBlock>
                <TextBlock Grid.Column="0" HorizontalAlignment="Right" Grid.Row="1"  Foreground="Gray" Text="关键字：">
                </TextBlock>
                <TextBlock Grid.Column="1" TextWrapping="Wrap" Grid.Row="1"  Text="{Binding Path=SelectedResource.KeyWords,Mode=OneWay}">
                </TextBlock>
                <TextBlock Grid.Column="0" HorizontalAlignment="Right" Grid.Row="2"  Foreground="Gray" Text="所属年龄段：">
                </TextBlock>
                <TextBlock Grid.Column="1" TextWrapping="Wrap" Grid.Row="2"  Text="{Binding Path=SelectedResource.SuitableAges,Mode=OneWay,Converter={StaticResource agesConverter}}">
                </TextBlock>
                <!--<TextBlock Grid.Column="0"  HorizontalAlignment="Right" Grid.Row="3"  Foreground="Gray" Text="故事简介：">
                </TextBlock>
                <TextBlock Grid.Column="1" TextWrapping="Wrap" Grid.Row="3"  Text="{Binding Path=SelectedResource.Description,Mode=OneWay}">
                </TextBlock>--> 
            </Grid>            
        </GroupBox>
        
        <Border Name="MaskBorder" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="2"  Panel.ZIndex="1000" >
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,-0.2">
                    <GradientStop Color="#FFA0E8FF"/>
                    <GradientStop Color="#FFFEFEFE" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <TextBlock FontSize="13"  VerticalAlignment="Center" HorizontalAlignment="Center">加载中... ...</TextBlock>
        </Border>
    </Grid>
</UserControl>
